//
//  OptionCardView.swift
//  Game
//
//  Created by woniu on 2025/9/2.
//

import UIKit

final class OptionCardView: UIControl {
    private let titleLabel = UILabel()
    private let container = UIView()

    var cornerRadius: CGFloat = 14 { didSet { container.layer.cornerRadius = cornerRadius } }
    var padding: UIEdgeInsets = UIEdgeInsets(top: 10, left: 16, bottom: 10, right: 16) { didSet { setNeedsLayout() } }

    var text: String? { didSet { titleLabel.text = text } }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setup()
    }

    private func setup() {
        addSubview(container)
        container.layer.cornerRadius = cornerRadius
        container.layer.masksToBounds = true
        container.backgroundColor = UIColor.systemYellow

        titleLabel.font = UIFont.systemFont(ofSize: 20, weight: .bold)
        titleLabel.textColor = UIColor.black
        container.addSubview(titleLabel)
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        container.frame = bounds
        titleLabel.frame = bounds.inset(by: padding)
    }

    func applyBackground(color: UIColor) {
        container.backgroundColor = color
    }
}



